﻿using System.Linq;
using System.Linq.Dynamic;
using System.Security.Cryptography.X509Certificates;
using System.Web.Mvc;
using QDT.Core.Domain;
using QDT.Core.Domain.Enums;
using QDT.Services.ArticleMoudule;
using QDT.Web.Helper;

namespace QDT.Web.Controllers
{
    public class ArticleController : BaseController {
        private readonly IArticleService _articleService;

        public ArticleController(IArticleService articleService) {
            _articleService = articleService;
        }

        [OutputCache(Duration =60,VaryByParam = "id")]
        public ActionResult ShowDetail(int id) {
            var data = _articleService.GetArticleById(id);
            if (data == null || !data.IsEffect) return HttpNotFound();
            return View(data.ToModel());
        }

        [OutputCache(Duration = 60, VaryByParam = "id")]
        public ActionResult ShowDetailMedia(int id)
        {
            var data = _articleService.GetArticleById(id);
            if (data == null || !data.IsEffect) return HttpNotFound();
            return View(data.ToModel());
        }

        public ActionResult List(int page=1,int size=6,string temp="") {

//            var cate = _articleService.GetCateTemp(cid);

            var data = _articleService.QueryList(page, size);
            var model = data.ToModelList();
            
            if(string.IsNullOrWhiteSpace(temp)){
                return View("_ArticalCate", model);
            }
            return View(temp, model);
        }

        public ActionResult Agreement()
        {
            return View();
        }

        public ActionResult Agreement2()
        {
            return View();
        }

        /// <summary>
        /// 通过视图名字获得静态的页面
        /// </summary>
        /// <param name="viewName"></param>
        /// <returns></returns>
        public ActionResult Static(string viewName) {

            return View(viewName);
        }

        /// <summary>
        /// 公告
        /// </summary>
        /// <returns></returns>
        public ActionResult News(int page=1,int size=10) {

            var data = _articleService.QueryArticle(page, size, ArticleType.Notice);

            var model = data.ToModelList();

            return View(model);
        }

    }
}
